package lcmpt;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.io.FileNotFoundException;

import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.WindowConstants;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeModel;

public final class LCMPTasTree {
	public static void main(final String[] args) throws FileNotFoundException {
		final JFrame frame = new JFrame("Hierarchische Darstellung von LCPMT");
		JSplitPane splitPane = new JSplitPane();
		frame.add(splitPane, BorderLayout.CENTER);
		// Erzeugen der Baumstruktur, des Modells und des Bedienelements
		final MutableTreeNode rootNode = new LCMPTReader()
				.createTreeStructure();
		final TreeModel treeModel = new DefaultTreeModel(rootNode);
		final JTree tree = new JTree(treeModel);

		splitPane.setLeftComponent(new JScrollPane(tree));

		JEditorPane editPane = new JEditorPane("text/html", "");
		editPane.setEditable(false);
		final JScrollPane scrollpane = new JScrollPane(editPane);
		splitPane.setRightComponent(scrollpane);

		Dimension d = frame.getToolkit().getScreenSize();
		frame.setSize((int) (2 * d.getWidth() / 3),
				(int) (5 * d.getHeight()) / 6);
		frame.setLocation((int) (d.getWidth() - frame.getWidth()) / 2, 0);
		splitPane.setDividerLocation(frame.getSize().width / 4);

		tree.addTreeSelectionListener(new LCMPTTreeSelectionListener(editPane,
				scrollpane));
		frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}

}
